/*
 * @Description: 新建
 * @Author: Zzt
 * @Date: 2022-12-21 17:02:19
 * @LastEditTime: 2023-02-07 17:30:08
 */

import { useEffect } from 'react';
import { Button, Form, Modal } from 'antd';
import { useBusinessGuidanceContext } from '../../contexts/BusinessGuidanceContext';
import FromList from './FromList';
import TableList from './TableList';

const CreateBusinessDialog = (props: any) => {
  const { visible, onClose } = props;
  const { addAnnualList, enclosureList, ClearAnnex } = useBusinessGuidanceContext();
  const [form] = Form.useForm();

  useEffect(() => {
    ClearAnnex();
  }, [visible]);
  const onCancel = () => {
    onClose();
  };

  /**
   * @description 提交表单，触发onFinish方法
   */
  const submitFunc = () => {
    form.submit();
  };

  // 新增排序方法
  const onFinish = (values: any) => {
    addAnnualList({
      ...values,
      attachmentJsonDTOS: enclosureList
    });
    onClose();
  };
  return (
    <Modal
      title="年检审核资料-新增"
      visible={visible}
      width={600}
      destroyOnClose
      onCancel={onCancel}
      footer={[
        <Button key="close" onClick={onCancel}>
          关闭
        </Button>,
        <Button
          key="save"
          type="primary"
          onClick={() => {
            submitFunc();
          }}
        >
          保存
        </Button>
      ]}
    >
      <Form
        labelCol={{ span: 5 }}
        wrapperCol={{ span: 19 }}
        preserve={false}
        form={form}
        onFinish={onFinish}
        labelAlign={'left'}
      >
        <FromList data={''} form={form} />
      </Form>
      <TableList />
    </Modal>
  );
};
export default CreateBusinessDialog;
